import request from '@/config/axios'

const baseURL = '/official-website/unit/banner'

export type BannerDetail = {
  id?: string
  bannerName: string
  bannerType: number
  bannerUrl: string
  switchJump: number
  jumpPage: string //跳转地址
  sortNo: number //排序
}

export interface GetBanner extends PageParam {
  bannerName?: string
  bannerType?: number
}

// 创建banner
export const bannerCreate = async (data: BannerDetail) => {
  return await request.post<boolean>({
    url: `${baseURL}/create`,
    data
  })
}

// 根据bannerid获取banner详情
export const getBannerById = async (id: string) => {
  return await request.get<BannerDetail>({
    url: `${baseURL}/get-banner-by-id`,
    params: { id }
  })
}

// 更新banner
export const updateBanner = async (data: BannerDetail) => {
  return await request.post<boolean>({
    url: `${baseURL}/update`,
    data
  })
}

// 删除banner
export const deleteBanner = async (id: string) => {
  return await request.delete<boolean>({
    url: `${baseURL}/delete?id=` + id
  })
}

// banner分页查询
export const getPageBanner = async (data: GetBanner) => {
  return await request.post({
    url: `${baseURL}/page`,
    data
  })
}
